package net.sudot.chess.business.controller.web;

import net.sudot.chess.business.controller.AbstractBaseController;
import net.sudot.chess.business.model.Customer;
import net.sudot.chess.business.model.OrderGame;
import net.sudot.chess.business.service.OrderGameService;
import net.sudot.commons.pagination.PageRequest;
import net.sudot.commons.security.LoginUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 游戏订单
 *
 * @author tangjialin on 2018-03-22.
 */
@Controller
@RequestMapping(value = "/order/game")
public class OrderGameController extends AbstractBaseController {

    @Resource
    private OrderGameService orderGameService;

    /**
     * 游戏订单数据列表
     *
     * @param page 分页参数
     * @return 返回订单数据列表
     */
    @PostMapping("/list")
    @ResponseBody
    public List<OrderGame> list(@RequestBody PageRequest page, @LoginUser Customer customer) {
        List<OrderGame> list = orderGameService.findList(page, customer.getId());
        return list;
    }

    /**
     * 充值订单状态
     *
     * @return 返回订单状态
     */
    @PostMapping("/status")
    @ResponseBody
    public Map<String, String> status() {
        Map<String, String> statusMapping = new HashMap<>();
        for (OrderGame.Status status : OrderGame.Status.values()) {
            statusMapping.put(status.name(), status.memo());
        }
        return statusMapping;
    }

}
